using LiJ.Http.Mos;
using LiJ.Pay.WeiXin.Cash.Mos;
using LiJ.Pay.WeiXin.SysTools;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;

namespace LiJ.Pay.WeiXin.Cash
{
	public class WxPayCashApi : WxPayBaseApi
	{
		public WxPayCashApi(WxPayCenterConfig config)
			: base(config)
		{
		}

		/// <summary>
		///  企业付款接口
		/// </summary>
		/// <param name="cashReq"></param>
		/// <returns></returns>
		public async Task<WxPayTransferCashResp> TransferCashAsync(WxPayTransferCashReq cashReq)
		{
			string addressUrl = "https://api.mch.weixin.qq.com" + "/mmpaymkttransfers/promotion/transfers";
			SortedDictionary<string, object> dics = cashReq.GetDics();
			dics.Add("mch_appid", base.ApiConfig.AppId);
			dics.Add("mchid", base.ApiConfig.MchId);
			base.CompleteDicSign(dics);
			LHttpRequest LHttpRequest = new LHttpRequest();
			LHttpRequest.HttpMothed = HttpMothed.Post;
			LHttpRequest.AddressUrl = addressUrl;
			LHttpRequest.CustomBody = dics.ProduceXml();
			return await base.RestCommonAsync(LHttpRequest, (Func<HttpResponseMessage, Task<WxPayTransferCashResp>>)null, base.GetCertHttpClient());
		}

		/// <summary>
		/// 获取企业付款信息
		/// </summary>
		/// <param name="partner_trade_no"></param>
		/// <returns></returns>
		public async Task<WxPayGetTransferCashResp> GetTransferCashAsync(string partner_trade_no)
		{
			string addressUrl = "https://api.mch.weixin.qq.com" + "/mmpaymkttransfers/gettransferinfo";
			SortedDictionary<string, object> xmlDirs = new SortedDictionary<string, object>
			{
				["nonce_str"] = SysUtil.GenerateNonceStr(),
				["partner_trade_no"] = partner_trade_no
			};
			return await base.PostApiAsync(addressUrl, xmlDirs, (Func<HttpResponseMessage, Task<WxPayGetTransferCashResp>>)null, base.GetCertHttpClient(), (Action<SortedDictionary<string, object>>)null);
		}
	}
}
